package com.weijin.springbootbase.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Author WeiJin
 * @Version 1.0
 * @Date 2025/3/11 10:54
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())     //用于生成信息
                .select()      //select()返回一个ApiSelectorBuilder实例，用来控制接口被swagger做成文档
                .apis(RequestHandlerSelectors.basePackage("com.weijin.springbootbase.controller"))    //指定扫描哪个包
                .paths(PathSelectors.any()) //选择所有api
                .build();
    }

    /**
     * 定义api主界面信息
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("springboot基础项目搭建")  //定义自己api的标题
                .description("搭建一个基本的springboot项目")  //描述整体的api
                .termsOfServiceUrl("")  //定义服务器域名
                .version("1.0")     //定义版本
                .build();
    }
}
